<?php
require_once("config/data.php");
global $dzsxDB;
if(!isset($_SESSION['TeacherId']))
  redirect("index.php");
else
  $v=$_SESSION['TeacherId'];
      //获得action参数
  $action = $_GET['action'];
  switch ($action)
    {
     /**
     实训项目列表查询
     **/
     case 'sxxmlist' : //列表
       $page = $_GET['page'];  //获取请求的页数
       $limit = $_GET['rows']; //获取每页显示记录数
       $sidx = $_GET['sidx'];  //获取默认排序字段 
       $sord = $_GET['sord'];  //获取排序方式
     //$page = 1;
    //$limit = 12;
    // $sidx = 'ExpId';
    // $sord = 'asc';
       if (!$sidx)
         $sidx = 1;

       //查询记录总数
        $dzsxDB->QueryTeacherExpinfo->Active = False;
        $dzsxDB->QueryTeacherExpinfo->SQL ="SELECT ExpId FROM sxxmlist where TeacherId='$v'";
        $dzsxDB->QueryTeacherExpinfo->Active = True;
        $count=$dzsxDB->QueryTeacherExpinfo->RecordCount; //获取总记录数

       //根据记录数分页
       if( $count >0 )
         {
          $total_pages = ceil($count/$limit);
         }
       else
        {
         $total_pages = 0;
        }
      if ($page > $total_pages) $page=$total_pages;
      $start = $limit*$page - $limit; // do not put $limit*($page - 1)
      //执行分页SQL
      $dzsxDB->QueryTeacherExpinfo->Active = False;
      $dzsxDB->QueryTeacherExpinfo->SQL ="Select * From sxxmlist Where TeacherId = '$v' ORDER BY $sidx $sord LIMIT $start , $limit";
      $dzsxDB->QueryTeacherExpinfo->Active = True;
      $dzsxDB->QueryTeacherExpinfo->first();
      $responce->page = $page;  //当前页
      $responce->total = $total_pages; //总页数
      $responce->records = $count; //总记录数
      $i = 0;
        //循环读取数据
      while (!$dzsxDB->QueryTeacherExpinfo->EOF)
      {
            $row=array();
            $row=$dzsxDB->QueryTeacherExpinfo->AssociativeFieldValues;
            $responce->rows[$i]['id'] = $row['ExpId'];
            $expid=$row['ExpId'] ;
            $expshzt=$row['Expshzt'];
            $editjs='var target = event.target || event.srcElement;
              $.fancybox({
                "href":"modifysxxm.php?modifyId="+target.id,
                "onClosed":function(){$("#sxxmlist").trigger("reloadGrid");
              }})';
            $deljs='var target = event.target || event.srcElement;
                    location.replace("teacher.php?delid="+target.id);';
            if($expshzt==0)
             {
              $optedit ="<a id='".$expid."' style='color:blue;cursor:pointer' onclick='".$editjs."'>修改|</a>";
              $optdel="<a id='".$expid."'style='color: blue;cursor:pointer' onclick='".$deljs."'>删除</a>";

             }
            else
             {
              $optedit="<a id='".$expid."' style='color: #C0C0C0;cursor:pointer'>修改|</a>";
              $optdel="<a id='".$expid."' style='color: #C0C0C0;cursor:pointer'>删除</a>";
             }
            $opt=$optedit.$optdel;
            $responce->rows[$i]['cell'] = array (
                $row['ExpId'],
                $row['ExpName'],
                $row['CourseName'],
                $row['ClassName'],
                $row['keshi'],
                $row['Expshrq'],
                $row['Expshzt'],
                $row['Expfbzt'],
                $opt
            );
          $i++;
          $dzsxDB->QueryTeacherExpinfo->next();
        }
        echo json_encode($responce);  //输出JSON数据
        break;

     /**
     实训报告列表查询
     **/
    case'sxbglist':
       $page = $_GET['page'];  //获取请求的页数
       $limit = $_GET['rows']; //获取每页显示记录数
       $sidx = $_GET['sidx'];  //获取默认排序字段 
       $sord = $_GET['sord'];  //获取排序方式
     //$page = 1;
    //$limit = 12;
    // $sidx = 'ExpId';
    // $sord = 'asc';
       if (!$sidx)
         $sidx = 1;

       //查询记录总数
        $dzsxDB->QuerySxbgList->Active = False;
        $dzsxDB->QuerySxbgList->SQL ="SELECT ReportId From sxbglist where TeacherId='$v'";
        $dzsxDB->QuerySxbgList->Active = True;
        $count=$dzsxDB->QuerySxbgList->RecordCount; //获取总记录数

       //根据记录数分页
       if( $count >0 )
         {
          $total_pages = ceil($count/$limit);
         }
       else
        {
         $total_pages = 0;
        }
      if ($page > $total_pages) $page=$total_pages;
      $start = $limit*$page - $limit; // do not put $limit*($page - 1)
      //执行分页SQL
      $dzsxDB->QuerySxbgList->Active = False;
      $dzsxDB->QuerySxbgList->SQL ="Select * From sxbglist
       Where TeacherId = '$v' ORDER BY $sidx $sord LIMIT $start , $limit";
      $dzsxDB->QuerySxbgList->Active = True;
      $dzsxDB->QuerySxbgList->first();
      $responce->page = $page;  //当前页
      $responce->total = $total_pages; //总页数
      $responce->records = $count; //总记录数


      $i = 0;
      while (!$dzsxDB->QuerySxbgList->EOF)//循环读取数据
      {
        $row=array();
        $row=$dzsxDB->QuerySxbgList->AssociativeFieldValues;
        $responce->rows[$i]['id'] = $row['ReportId'];
        switch($row['sxcj'])
          {
           case 0:$sxcj='未评阅'; break;
           case 1:$sxcj='优秀';break;
           case 2:$sxcj='良好';break;
           case 3:$sxcj='合格';break;
           case 4:$sxcj='不合格';break;
           case 5:$sxcj='重做';break;
          }
        $repid=$row['ReportId'];
        $scorejs='var target = event.target || event.srcElement;
        $.fancybox({
          "href":"sxbg.php?RepScoreId="+target.id,
          "width":835,
          "height":625,
          "autoDimensions":false,
          "type":"iframe",
          "onClosed":function(){$("#sxbglist").trigger("reloadGrid");}
        })';
        $opt="<a id='".$repid."' style='color:blue;cursor:pointer' onclick='".$scorejs."'>评阅</a>";;
        $responce->rows[$i]['cell'] = array (
          $row['ReportId'],
          $row['ExpName'],
          $row['CourseName'],
          $row['StudentName'],
          $row['ClassName'],
          $row['ProfName'],
          $row['tjrq'],
          $sxcj,
          $opt
          );
        $i++;
        $dzsxDB->QuerySxbgList->next();
      }
        echo json_encode($responce);  //输出JSON数据
        break;

    //实训项目审核列表
    case 'sxxmshlist':
     if($_SESSION['TeacherType']==2||$_SESSION['TeacherType']==3)
      {
       $page = $_GET['page'];  //获取请求的页数
       $limit = $_GET['rows']; //获取每页显示记录数
       $sidx = $_GET['sidx'];  //获取默认排序字段 
       $sord = $_GET['sord'];  //获取排序方式
       if (!$sidx)
         $sidx = 1;

       //查询记录总数
        $dzsxDB->Querysxxmshlist->Active = False;
        $dzsxDB->Querysxxmshlist->SQL ="SELECT ExpId FROM sxxmlist";
        $dzsxDB->Querysxxmshlist->Active = True;
        $count=$dzsxDB->Querysxxmshlist->RecordCount; //获取总记录数

       //根据记录数分页
       if( $count >0 )
         {
          $total_pages = ceil($count/$limit);
         }
       else
        {
         $total_pages = 0;
        }
      if ($page > $total_pages) $page=$total_pages;
      $start = $limit*$page - $limit; // do not put $limit*($page - 1)
      //执行分页SQL
      $dzsxDB->Querysxxmshlist->Active = False;
      $dzsxDB->Querysxxmshlist->SQL ="Select * From sxxmlist ORDER BY $sidx $sord LIMIT $start , $limit";
      $dzsxDB->Querysxxmshlist->Active = True;
      $dzsxDB->Querysxxmshlist->first();
      $responce->page = $page;  //当前页
      $responce->total = $total_pages; //总页数
      $responce->records = $count; //总记录数
      $i = 0;
        //循环读取数据
      while (!$dzsxDB->Querysxxmshlist->EOF)
      {
            $row=array();
            $row=$dzsxDB->Querysxxmshlist->AssociativeFieldValues;
            $responce->rows[$i]['id'] = $row['ExpId'];
            $responce->rows[$i]['cell'] = array (
                $row['ExpId'],
                $row['ExpName'],
                $row['CourseName'],
                $row['ClassName'],
                $row['keshi'],
                $row['Expshrq'],
                $row['Expshzt']
            );
          $i++;
          $dzsxDB->Querysxxmshlist->next();
        }
        echo json_encode($responce);  //输出JSON数据
      }
      break;

    /**实训报告管理**/
    case'sxbggllist':
    if($_SESSION['TeacherType']==3)
     {
       $page = $_GET['page'];  //获取请求的页数
       $limit = $_GET['rows']; //获取每页显示记录数
       $sidx = $_GET['sidx'];  //获取默认排序字段 
       $sord = $_GET['sord'];  //获取排序方式
     //$page = 1;
    //$limit = 12;
    // $sidx = 'ExpId';
    // $sord = 'asc';
       if (!$sidx)
         $sidx = 1;

       //查询记录总数
        $dzsxDB->QuerySxbgList->Active = False;
        $dzsxDB->QuerySxbgList->SQL ="SELECT ReportId From sxbglist";
        $dzsxDB->QuerySxbgList->Active = True;
        $count=$dzsxDB->QuerySxbgList->RecordCount; //获取总记录数

       //根据记录数分页
       if( $count >0 )
         {
          $total_pages = ceil($count/$limit);
         }
       else
        {
         $total_pages = 0;
        }
      if ($page > $total_pages) $page=$total_pages;
      $start = $limit*$page - $limit; // do not put $limit*($page - 1)
      //执行分页SQL
      $dzsxDB->QuerySxbgList->Active = False;
      $dzsxDB->QuerySxbgList->SQL ="Select * From sxbglist ORDER BY $sidx $sord LIMIT $start , $limit";
      $dzsxDB->QuerySxbgList->Active = True;
      $dzsxDB->QuerySxbgList->first();
      $responce->page = $page;  //当前页
      $responce->total = $total_pages; //总页数
      $responce->records = $count; //总记录数


      $i = 0;
      while (!$dzsxDB->QuerySxbgList->EOF)//循环读取数据
      {
        $row=array();
        $row=$dzsxDB->QuerySxbgList->AssociativeFieldValues;
        $responce->rows[$i]['id'] = $row['ReportId'];
        switch($row['sxcj'])
          {
           case 0:$sxcj='未评阅'; break;
           case 1:$sxcj='优秀';break;
           case 2:$sxcj='良好';break;
           case 3:$sxcj='合格';break;
           case 4:$sxcj='不合格';break;
           case 5:$sxcj='重做';break;
          }
        $repid=$row['ReportId'];
        $scorejs='var target = event.target || event.srcElement;
        $.fancybox({
          "href":"sxbg.php?RepScoreId="+target.id,
          "width":835,
          "height":625,
          "autoDimensions":false,
          "type":"iframe",
          "onClosed":function(){$("#sxbglist").trigger("reloadGrid");}
        })';
        $opt="<a id='".$repid."' style='color:blue;cursor:pointer' onclick='".$scorejs."'>查阅</a>";;
        $responce->rows[$i]['cell'] = array (
          $row['ReportId'],
          $row['ExpName'],
          $row['CourseName'],
          $row['StudentName'],
          $row['ClassName'],
          $row['ProfName'],
          $row['tjrq'],
          $sxcj,
          $opt
          );
        $i++;
        $dzsxDB->QuerySxbgList->next();
      }
        echo json_encode($responce);  //输出JSON数据
    }
        break;


    case '' :
      echo 'Bad request.';
      break;

   }
?>